package com.ruoyi.web.controller.wlsggk;


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.waterdrop.wlsggk.pojo.Material;
import com.waterdrop.wlsggk.service.MaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/wlsggk/material")
public class MaterialController extends BaseController {

    @Autowired
    private MaterialService materialService;

    /**
     * 获取物料列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Material material) {
        startPage();
        List<Material> list = materialService.selectMaterialList(material);
        return getDataTable(list);
    }

    /**
     * 删除物料信息
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(materialService.deleteWlsggkMaterial(ids));
    }

    /**
     * 根据物料id查询
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return success(materialService.selectWlsggkMaterialById(id));
    }

    /**
     * 新增物料
     */
    @PostMapping
    public AjaxResult add(@Validated @RequestBody Material material) {
        return toAjax(materialService.insertWlsggkMaterial(material));
    }

    /**
     * 修改物料信息
     */
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody Material material) {
        return toAjax(materialService.updateWlsggkMaterial(material));
    }


}
